package com.bestcem.xm.member.util;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;

/**
 * @author ming.xue <ming.xue@idiaoyan.com>
 * @desc 参数验证工具
 * @date 2021-08-17
 */
public class ValidationUtil {
    /**
     * 参数验证
     *
     * @param param
     * @return
     */
    public static Set<ConstraintViolation<Object>> validateParam(Object param) {
        if (Objects.isNull(param)) {
            return Collections.emptySet();
        }
        Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
        return validator.validate(param);
    }
}
